#include "OtherRT.h"

void OtherRT::deleteProduct(vector<Product> &prods) {
    int tempProductId;

    cout << "Product ID: ";
    cin >> tempProductId;

    Product prd; // temporary product found
    bool isExist = false;
    for (int i = 0; i < prods.size(); ++i) {
        // input product_id valid
        if (prods[i].get_prod_id() == tempProductId) {
            prods[i].set_cat_id(999);					// Cat ID= 999; Mean:Delete relation between product and category (Delete Product From category)
            cout << "Product Deleted from Category!"<< endl;
            isExist = true;
            break;
        }
    }
    // input product id not valid
    if (!isExist) {
        cout << "Product id " << tempProductId << " not found." << endl;
        return;
    }
}

void OtherRT::changePrice(vector<Product> &prods) {
    int tempProductId;
    int newPrice;

    cout << "Product ID: "; // Insert Product Id
    cin >> tempProductId;


    Product prd; // temporary product found
    bool isExist = false;
    for (int i = 0; i < prods.size(); ++i) {
        // input product_id valid
        if (prods[i].get_prod_id() == tempProductId) {


            cout << "Insert new price: ";
            cin >> newPrice;
            //change Price
			prods[i].set_price(newPrice);
            cout << "Product price changed." << endl;
            isExist = true;
            break;
        }
    }
    // input product id not valid
    if (!isExist) {
        cout << "Product id " << tempProductId << " not found." << endl;
        return;
    }
}

void OtherRT::addNewCategory(vector<Category> &cats) {
    int newCategoryID;
    string newCategoryName;
	bool isExist;

    cout << "Insert Category ID : "; // Insert category Id
    cin >> newCategoryID;

	// check existing category id
	for (int i = 0; i < cats.size(); ++i) {
        if (cats[i].get_cat_id() == newCategoryID) {
            isExist = true;
			break;
        }
    }
    // input category id valid
    if (!isExist) {
		cout << "Insert Category Name : "; // Insert category name
		cin >> newCategoryName;
		// insert to Category
		cats.push_back(Category(newCategoryID, newCategoryName));
		cout << "New Category Inserted." << endl;
        return;
    }
   
}
